package com.qf.utils;

import com.qf.entity.Menu;

import java.util.ArrayList;
import java.util.List;

/**
 * 2019/12/11
 * 郭程鹏
 * springboot_oa_five
 * 面向代码面向君,不负时光不负卿
 */

public class MenuUtil {

    public static List<Menu> firstMenu(List<Menu> menus){
        //2.1 对菜单列表分级
        ArrayList firstMenu= new ArrayList();//保存一级菜单
        for (Menu menu : menus) {
            if(menu.getSuperMenuId()==0){ //一级菜单
                ArrayList secondList= new ArrayList();//保存二级菜单
                for (Menu second : menus) {
                    if(menu.getMenuId()==second.getSuperMenuId()){//如果一级菜单的id(menuid)==二级菜单的父id(upmenuid)
                        secondList.add(second);
                    }
                }
                //将二级菜单的集合封装到一级菜单中
                menu.setMenus(secondList);
                //将一级菜单在添加到集合中
                firstMenu.add(menu);
            }
        }
        return firstMenu;
    }
}
